<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title> 卡 盟 管 理 员 登 录 页 </title>
    <link rel="stylesheet" href="../layui/css/layui.css">
    <style>
        /*.login-container {*/
        /*    margin: 0 auto;*/
        /*    width: 50%;*/
        /*}*/
        /*.login-container .layui-form-item {*/
        /*    margin-bottom: 20px;*/
        /*}*/
        /*.login-container .layui-input-block {*/
        /*    width: 80%;*/
        /*    margin: 0 auto;*/
        /*}*/
        /*.login-container .layui-btn {*/
        /*    width: 100%;*/
        /*}*/
        body {
            background-color: #f2f2f2;
            display: flex;
            align-items: center;
            justify-content: center;
            height: 100vh;
            background-image: url("../layui/img/adminloginback.jpg");
            background-size: cover;
        }
        .login-container {
            margin: 0 auto;
            /*width: 400px;*/
            width: 50%;
            padding: 20px;
            background-color: #fff;
            border-radius: 5px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            background-color: rgba(0, 0, 0, 0); /* 使用rgba()函数设置背景颜色和透明度 */
        }
        .login-container h2 {
            text-align: center;
            font-size: 24px;
            margin-bottom: 20px;
        }
        .login-container .layui-form-item {
            margin-bottom: 20px;
        }
        .login-container .layui-input-block {
            width: 100%;
        }
        .login-container .layui-input-block input {
            width: 100%;
            font-size: 14px;
        }
        .login-container .layui-btn-container {
            text-align: center;
        }
        .login-container .layui-btn-container .layui-btn {
            width: 120px;
        }
        .login-container .layui-btn-container .layui-btn:first-child {
            margin-right: 20px;
        }

        /**加深登录界面字体*/
        .bold-label {
            font-weight: bold;
        }
    </style>

</head>
<script src="../layui/layui.js"></script>
<body>
<div class="layui-container">
    <div class="login-container">
    <form class="layui-form" id="login-form" method="post">
        <div class="layui-form-item">
            <label class="layui-form-label">账号</label>
            <div class="layui-input-block">
                <input type="text" name="username" lay-verify="required" placeholder="请输入账号" autocomplete="off" class="layui-input" style="width: 60%;">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-block">
                <input type="password" name="password" lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input" style="width: 60%;">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="login">登录</button>
            </div>
        </div>
    </form>
        </div>
</div>

<script>
    layui.use(['form', 'layer','jquery'], function () {
        var form = layui.form;
        var layer = layui.layer;
        var $ = layui.jquery;

        // 监听表单提交事件
        form.on('submit(login)', function (data) {
            // 阻止表单提交
            data.preventDefault();

            // 获取表单数据
            var username = data.field.username;
            var password = data.field.password;


            // 构建请求数据
            var requestData = {
                username: username,
                password: password
            };

            //参数传递检测
            console.log(requestData);

            // 发送登录请求
            $.ajax({
                url: '/admin/login', // 后端登录接口的 URL
                type: 'POST',
                data: requestData,
                success: function (response) {
                    // 登录成功
                    if (response.success) {
                        layer.msg('登录成功', { icon: 1 });
                        window.location.href = 'home.html';
                    } else {
                        layer.msg('用户名或密码错误', { icon: 2 });
                    }
                },
                error: function (xhr, status, error) {
                    // 处理错误情况
                    //console.log(error);
                    layer.msg('登录请求失败', { icon: 2 });
                }
            });

            return false; // 阻止表单跳转
        });
    });
</script>
</body>
</html>
